#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QObject>
#include <QFileDialog>

class ImageLoader : public QObject {
    Q_OBJECT
public:
    explicit ImageLoader(QObject *parent = nullptr) : QObject(parent) {}

    Q_INVOKABLE void selectImage() {
        QString filePath = QFileDialog::getOpenFileName(nullptr, "选择图片", "", "Images (*.png *.jpg *.jpeg *.bmp)");
        if (!filePath.isEmpty()) {
            emit imageSelected(filePath);
        }
    }

signals:
    void imageSelected(const QString &filePath);
};

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    qmlRegisterType<ImageLoader>("com.example.imageloader", 1, 0, "ImageLoader");

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
